package com.huashun.ship.run.shiplock.controller;

import com.huashun.ship.run.shiplock.dto.RestResultDTO;
import com.huashun.ship.run.shiplock.dto.ShipLockDetailDTO;
import com.huashun.ship.run.shiplock.dto.ShipLockOverviewDTO;
import com.huashun.ship.run.shiplock.service.ShipLockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 船舶过闸信息Controller
 * @author yzh
 * @version 0.0.1
 * @since 20200510
 */
@RestController
@RequestMapping("shiplockInfo")
@Api(tags = "船舶过闸信息")
@Slf4j
public class ShiplockInfoController {
    @Autowired
    private ShipLockService shipLockService;

    @RequestMapping(value = "/getShiplockOverviews", method = RequestMethod.GET)
    @ApiOperation(value = "获取船舶过闸情况总览数据"
            , notes = "获取西江各枢纽船闸的过闸情况总览数据，data中除最后一个元素外的其它元素为各船闸的总览数据，最后一个元素为各船闸的汇总数据")
    public RestResultDTO<List<ShipLockOverviewDTO>> getShiplockSchedule(){
        RestResultDTO<List<ShipLockOverviewDTO>> shiplockOverviewDTO = new RestResultDTO<List<ShipLockOverviewDTO>>();

        List<ShipLockOverviewDTO> overviewDTOs = this.shipLockService.getAllShipLockOverviewDTOs();

        shiplockOverviewDTO.setData(overviewDTOs);

        return shiplockOverviewDTO;
    }

    /**
     * 抓取船舶过闸明细数据
     * @param shipLockCode
     * @param direction
     * @return
     */
    @RequestMapping(value = "/getShiplockDetail", method = RequestMethod.GET)
    @ApiOperation(value = "获取船闸过闸明细数据"
            , notes = "获取指定船闸，指定方向的过闸情况明细数据")
    public RestResultDTO<List<ShipLockDetailDTO>> getShiplockDetail(
            @ApiParam(name = "shipLockCode", value = "船闸代码", required = true) @RequestParam(value = "shipLockCode", required = true)String shipLockCode
            , @ApiParam(name = "direction", value = "航行方向，up表示上行，down表示下午，默认为上行", required = false, defaultValue = "up") @RequestParam(value = "direction", required = false, defaultValue = "up")String direction){
        RestResultDTO<List<ShipLockDetailDTO>> shiplockDetailDTO = new RestResultDTO<List<ShipLockDetailDTO>>();

        List<ShipLockDetailDTO> shipLockDetailDTOList = this.shipLockService.getShipLockDetailDTOs(shipLockCode, direction);
        shiplockDetailDTO.setData(shipLockDetailDTOList);

        return shiplockDetailDTO;
    }
}
